#!/bin/sh

echo "________________________________________________________________________"
echo "下面开始安装Git"
echo "========================================================================"
sudo apt-get install git -y
echo "________________________________________________________________________"
echo "下面开始安装ZIP"
echo "========================================================================"
sudo apt-get install zip -y
echo "________________________________________________________________________"
echo "下面开始下载Gitlab-ce-10.7.3"
echo "========================================================================"
wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/ubuntu/pool/trusty/main/g/gitlab-ce/gitlab-ce_10.7.3-ce.0_amd64.deb
echo "________________________________________________________________________"
echo "开始安装Gitlab-ce-10.7.3"
echo "========================================================================"
sudo dpkg -i gitlab-ce_10.7.3-ce.0_amd64.deb
# cd /opt/gitlab/embedded/service
# cp -r /opt/gitlab/embedded/service/gitlab-rails /opt/gitlab/embedded/service/gitlab-rails.old
# git clone https://gitlab.com/xhang/gitlab.git
# mv gitlab gitlab-rails.new
# cp -rf gitlab-rails.new gitlab-rails
# cp gitlab-rails.old/REVISION  gitlab-rails
# rm -rf /opt/gitlab/embedded/service/gitlab-rails/tmp
# rm -rf /opt/gitlab/embedded/service/gitlab-rails/log
echo "________________________________________________________________________"
echo "开始配置Gitlab-ce-10.7.3"
echo "========================================================================"
gitlab-ctl reconfigure
echo "________________________________________________________________________"
echo "重启Gitlab-ce-10.7.3"
echo "========================================================================"
gitlab-ctl restart
#下面开始安装汉化补丁
echo "________________________________________________________________________"
echo "下面开始安装汉化补丁"
echo "========================================================================"
gitlab_version=$(sudo cat /opt/gitlab/embedded/service/gitlab-rails/VERSION)
git clone https://gitlab.com/xhang/gitlab.git
cd gitlab
git fetch
git diff v${gitlab_version} v${gitlab_version}-zh > ../${gitlab_version}-zh.diff
sudo gitlab-ctl stop
cd ../
sudo patch -d /opt/gitlab/embedded/service/gitlab-rails -p1 < ${gitlab_version}-zh.diff
sudo gitlab-ctl start
echo "________________________________________________________________________"
echo "下面开始创建虚拟内存"
echo "========================================================================"
#下面开始创建虚拟内存
mkdir swap
cd swap
dd if=/dev/zero of=/swapfile1 bs=1024 count=4194304
mkswap /swapfile1
swapon /swapfile1
echo  "/swapfile1 swap swap defaults 0 0" >> /etc/fstab
echo "vm.swappiness = 100" >> /etc/sysctl.conf
echo "________________________________________________________________________"
echo "下面开始重启，重启后请等待120秒，访问自己的ip地址，刚开始会显示502，120秒后正常"
echo "========================================================================"
echo "重启执行sudo vim /opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml，编辑host修改ssh地址"
sudo reboot

